﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TVGuide.DataAccess;
using TVGuide.DataAccess.Repository;
using TVGuide.DataAccess.Common;

namespace TVGuide.Parser
{
    public class MainProgram
    {
        public static ProgramRepository pr = ProgramRepository.Instance();
        public static void UcomParseForWeek()
        {
            DateTime start = DateTime.Now;
            
            for (int i = 0; i < 7; i++)
            {
                List<Program> ucomPrList = UCOMParseEngine.ParseAll((DateTime)DateTime.Today.AddDays(i));

                if (ucomPrList.Count != 0)
                {
                    TVGuide.DataAccess.Utilsities.addPrograms(ucomPrList);
                }

            }
            Console.Write("Time elapsed " + (DateTime.Now.Minute - start.Minute) + " minutes.");
        }

        public static void EterParseForWeek()
        {
            DateTime start = DateTime.Now;

            for (int i = 0; i <= 7 - (int)DateTime.Today.DayOfWeek; i++)
            {
                List<Program> eterPrList = EterParserEngine.ParseAll((DateTime)DateTime.Today.AddDays(i));

                if (eterPrList.Count != 0)
                {
                    TVGuide.DataAccess.Utilsities.addPrograms(eterPrList);
                }

            }
            Console.Write("Time elapsed " + (DateTime.Now.Minute - start.Minute) + " minutes.");
        }

        public static void NTVParseForWeek()
        {
            for (int i = 0; i < 7; i++)
            {
                List<Program> ntvPrList = NTVPlusParseEngineWOTimeShift.ParseAll(DateTime.Today.AddDays(i)).Distinct().ToList();
                TVGuide.DataAccess.Utilsities.addPrograms(ntvPrList);


            }

        }

        public static void ParseForWeek()
        {
            var parsers = Parsers.ParsersList;
            foreach (var parser in parsers)
            {
                var programsList = parser.ParseProgramForWeek();
                if (programsList.Count != 0)
                {
                    TVGuide.DataAccess.Utilsities.addPrograms(programsList);
                }
            }
        }

        public static void EterParse()
        {
            EterParserEngine.ParseAll(DateTime.Today);
        }



        static void Main(string[] args)
        {
            Console.WriteLine(DateTime.Today);
            TVGuide.Common.Utils.ConvertToHyAMDate("Հինգշաբթի, 10 Նոյեմբեր");

        }

        public static void ParseNewUcomFromFile(string filePath)
        {
            List<Program> newUcom = UCOMParseEngineNew.ParseSpecificProgramFromFile(filePath);
            TVGuide.DataAccess.Utilsities.addPrograms(newUcom);
        }
    }
}
